﻿using System;
using Autodesk.Revit.UI;
using YJKRevitDimensionText.Forms;

namespace YJKRevitDimensionText.Utility
{
	public class RevitApplication : IExternalApplication
	{
		public bool IsHide { get; set; }

		public Result OnShutdown(UIControlledApplication application)
		{
			if (this.m_MyForm != null && this.m_MyForm.Visible)
			{
				this.m_MyForm.Close();
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public Result OnStartup(UIControlledApplication application)
		{
			this.m_MyForm = null;
			RevitApplication.thisApp = this;
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		public void ShowForm(UIApplication uiapp)
		{
			if (this.m_MyForm == null || this.m_MyForm.IsDisposed)
			{
				RequestHandler requestHandler = new RequestHandler();
				ExternalEvent exEvent = ExternalEvent.Create(requestHandler);
				this.m_MyForm = new DlgDimensionHide(exEvent, requestHandler, uiapp.ActiveUIDocument.Document.ActiveView.Id.ToString(), uiapp);
				this.m_MyForm.Show(WindowHelper.HWndRevit);
			}
		}

		public void WakeFormUp()
		{
			if (this.m_MyForm != null)
			{
				this.m_MyForm.WakeUp();
			}
		}

		internal static RevitApplication thisApp;

		public DlgDimensionHide m_MyForm;
	}
}
